package com.yzc.mihuyou.controller;


import com.yzc.mihuyou.entity.Compilations;
import com.yzc.mihuyou.entity.Iccomp;
import com.yzc.mihuyou.entity.User;
import com.yzc.mihuyou.mapper.IccompMapper;
import com.yzc.mihuyou.service.CompilationsService;
import com.yzc.mihuyou.service.IngvseService;
import com.yzc.mihuyou.service.InvitationService;
import com.yzc.mihuyou.util.ImgServe;
import com.yzc.mihuyou.util.TokenProccessor;
import com.yzc.mihuyou.vo.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 * 集合 前端控制器
 * </p>
 *
 * @author 易紫诚
 * @since 2022-04-28
 */
@RestController
@RequestMapping("/mihuyou/compilations")
public class CompilationsController {

    @Autowired
    CompilationsService compilationsService;
    @Autowired
    IccompMapper iccompMapper;
    @Autowired
    InvitationService invitationService;

    @Autowired
    TokenProccessor tokenProccessor;

    @PostMapping("addPos")
    public JsonResult addPos(MultipartFile photos,@RequestBody Compilations compilations){
        if(photos==null){
            compilations.setCompilationsImage("http://z534021l97.zicp.vip/pircevr/2022/04/29/cd77fee0-e155-4a16-b726-341d5835d89e.jpg");
        }else {
            compilations.setCompilationsImage(ImgServe.uploadImg(photos));
        }
        int i = compilationsService.addComImc(compilations);
        return new JsonResult(200,"添加成功");
    }


    @GetMapping("sels/{id}")
    public  JsonResult sel(@PathVariable("id") int id, String type, HttpServletRequest httpServletRequest){
        Long l=0L;
        String token = httpServletRequest.getHeader("token");
        User user=null;
        if(token!=null){
            user= tokenProccessor.verify(token);
        }
        if(user!=null){
            l=user.getUserId();
        }
        if(type==null){
            type=0+"";
        }
        return  new JsonResult(200,"查询成功",invitationService.sow(id,type,l));
    }

}

